{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "79826290-53d3-4655-a5c2-c1bc3cb2c452",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "姓名：王子涵,年龄：12,身高：120\n"
     ]
    }
   ],
   "source": [
    "# 字符串格式化\n",
    "\n",
    "s = \"姓名：{0},年龄：{1},身高：{2}\"\n",
    "print(s.format('王子涵', 12, 120))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "ffaae0a0-9379-43f5-8cc1-450e02d6e2d8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "#######Python#######\n"
     ]
    }
   ],
   "source": [
    "print(\"{:#^20}\".format(\"Python\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "007470b6-433e-4d39-b6a8-773cbd9ac69a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "**************************录音开始\n"
     ]
    }
   ],
   "source": [
    "print(\"{:*>30}\".format(\"录音开始\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "97ca0fcf-40c6-4866-a826-a0c8333ae7de",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3.14\n",
      "+3.14\n",
      "3\n",
      "05\n",
      "50\n",
      "1,000,000,000\n",
      "23.60%\n"
     ]
    }
   ],
   "source": [
    "# 数字格式\n",
    "\n",
    "# 保留小数后两位\n",
    "print(\"{:.2f}\".format(3.1415926)) # 3.14\n",
    "\n",
    "# 带符号暴力小数点后两位\n",
    "print(\"{:+.2f}\".format(3.1415926)) # +3.14\n",
    "\n",
    "# 不带小数点\n",
    "print(\"{:.0f}\".format(3.1455667)) # 3\n",
    "\n",
    "# 数字为0,填充左边,宽度为2\n",
    "print(\"{:0>2d}\".format(5)) # 05\n",
    "print(\"{:0<2d}\".format(5)) # 50\n",
    "\n",
    "# 以逗号分割的数字\n",
    "print(\"{:,}\".format(1000000000)) # 1,000,000,000\n",
    "\n",
    "# 带百分比\n",
    "print(\"{:.2%}\".format(0.236)) # 23.60%"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "576cb112-543f-4782-9ef2-f19d2b067acb",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
